#!/bin/bash
# This file a part of SHM. Copyright (C) Tom Li 2013.
# License: LGPL version 3 or later.


USERNAME=$1
DOMAIN=$2

read -r -d '' CONF << EOF
#!/sbin/runscript

depend() {
    need net
    use nginx
}

start() {
        su ${USERNAME} -c 'PHPRC=/home/${USERNAME}/etc/php5 PHP_FCGI_CHILDREN=2
                         /usr/bin/php-loop.pl /usr/bin/php-cgi -b /var/run/virtualhost/php-${DOMAIN}.sock >> /home/${USERNAME}/logs/php.log 2>&1 </dev/null & 
                         echo \$! >/var/php-nginx/${DOMAIN}.php.pid'
}

stop() {
        su ${USERNAME} -c 'kill \`cat /var/php-nginx/${DOMAIN}.php.pid\` ; sleep 1'
}
EOF

echo "$CONF"
